package test.core.data;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.junit.Test;

import hyl.core.MyCharset;
import hyl.core.MyFun;
import hyl.core.data.Bytes;
import hyl.core.data.BytesComparator;
import hyl.core.fun.MyByte;

public class testbytes {
	// @Test
	public void test1_0() {
		// String string="092374502934687@laks=29;";
		String string = "092374502934687@laks=29;@xlczvkq34)@vbxc?*";
		byte[] b1 = MyFun.str2Bytes(string, MyCharset._ASCII);
		byte bkey[] = { '@' };
		int 分割 = 1;// -1 ,0,1,2,3,4,5
		byte[][] b2 = MyFun.split(b1, bkey, 分割);
		for (int i = 0; i < b2.length; i++) {
			System.out.println("-1-" + new String(b2[i], MyCharset._ASCII));
		}
	}

	// @Test
	public void test1_1() {

		byte[] b1 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		byte[] b2 = MyFun.str2Bytes("qwerty", MyCharset._ASCII);
		byte[] b3 = MyFun.str2Bytes("!#!", MyCharset._ASCII);
		byte[] bb = MyFun.concat(b1, b2, b3);
		System.out.println(new String(bb, MyCharset._ASCII));
	}

	// @Test
	public void test1_2() {

		byte[] b1 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		byte[] b2 = MyFun.str2Bytes("qwerty", MyCharset._ASCII);
		byte[] b3 = MyFun.str2Bytes("!#!", MyCharset._ASCII);
		byte[] bb = MyFun.concat(new byte[] { '@', '@' }, b1, b2, b3);

		System.out.println(new String(bb, MyCharset._ASCII));
	}

	// @Test
	public void test1_3() {
//判断等式

		byte[] b1 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		byte[] b2 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);

		ConcurrentHashMap<byte[], String> mp = new ConcurrentHashMap<>();

		mp.put(b1, "等待");
		System.out.println(mp.get(b2) + Arrays.equals(b1, b2) + b1.equals(b2));
	}

	//@Test
	public void test1_4() {
		// 判断等式

		byte[] b1 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		byte[] b2 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		ByteBuffer bb1 = ByteBuffer.wrap(b1);
		bb1.flip();
		ByteBuffer bb2 = ByteBuffer.wrap(b2);
		bb2.flip();
		ConcurrentHashMap<ByteBuffer, String> mp = new ConcurrentHashMap<>();

		mp.put(bb1, "等待");
		System.out.println(mp.get(bb2) + bb1.equals(bb2));
	
	}
	//Bytes
	@Test
	public void test1_5() {
		// 判断等式

		byte[] b1 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		byte[] b2 = MyFun.str2Bytes("0923745029", MyCharset._ASCII);
		Bytes bb1 = new Bytes(b1);

		Bytes bb2 = Bytes.wrap(b2);

		ConcurrentHashMap<Bytes, String> mp = new ConcurrentHashMap<>();

		mp.put(bb1, "等待");
		System.out.println(mp.get(bb2) + bb1.equals(bb2)+bb1.hashCode());

	}
}
